﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class GUI_Pages_ParentRegistration1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime myDateTime = DateTime.Now;
        string year = myDateTime.Year.ToString();
        int yr = int.Parse(year);

        ArrayList ayear = new ArrayList();
        int i;
        for (i = 1950; i <= yr; i++)
        {
            String n = i.ToString();
            ayear.Add(n);

        }

        myear.DataSource = ayear;
        myear.DataBind();
        fyear.DataSource = ayear;
        fyear.DataBind();
    }

    protected DateTime getBirthDate(String d, String m, String y)
    {
        Int32 day = Int32.Parse(d);
        Int32 month = Int32.Parse(m);
        Int32 year = Int32.Parse(y);
        DateTime dt = new DateTime(year, month, day);
        return dt;
    }

    protected void parentsform1_Click(object sender, EventArgs e)
    {
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd1 = new SqlCommand("AccountIDAssignment", conn);
        cmd1.CommandType = CommandType.StoredProcedure;

        cmd1.Parameters.Add(new SqlParameter("@acctID", 1));
      
        conn.Open();
        int accID = Convert.ToInt32((decimal)cmd1.ExecuteScalar());
        conn.Close();

        SqlCommand cmd2 = new SqlCommand("ParentRegistration1", conn);
        cmd2.CommandType = CommandType.StoredProcedure;

        cmd2.Parameters.Add(new SqlParameter("@MEMail", mEmail.Text));
        cmd2.Parameters.Add(new SqlParameter("@MotherName", mName.Text));
        cmd2.Parameters.Add(new SqlParameter("@MDoB", getBirthDate(mday.SelectedValue, mmonth.SelectedValue, myear.SelectedValue)));
        cmd2.Parameters.Add(new SqlParameter("@MCellNo", mmob.Text));
        cmd2.Parameters.Add(new SqlParameter("@MPhoneNo", mphone.Text));
        cmd2.Parameters.Add(new SqlParameter("@MEmployment", memp.Text));
        cmd2.Parameters.Add(new SqlParameter("@MStreetAddress", maddress.Text));
        cmd2.Parameters.Add(new SqlParameter("@MArea", marea.Text));
        cmd2.Parameters.Add(new SqlParameter("@MPostalCode", mpost.Text));
        cmd2.Parameters.Add(new SqlParameter("@MCityID", 1));

        cmd2.Parameters.Add(new SqlParameter("@FEMail", fEmail.Text));
        cmd2.Parameters.Add(new SqlParameter("@FatherName", fName.Text));
        cmd2.Parameters.Add(new SqlParameter("@FDoB", getBirthDate(fday.SelectedValue, fmonth.SelectedValue, fyear.SelectedValue)));
        cmd2.Parameters.Add(new SqlParameter("@FCellNo", fmob.Text));
        cmd2.Parameters.Add(new SqlParameter("@FPhoneNo", fphone.Text));
        cmd2.Parameters.Add(new SqlParameter("@FEmployment", femp.Text));
        cmd2.Parameters.Add(new SqlParameter("@FStreetAddress", faddress.Text));
        cmd2.Parameters.Add(new SqlParameter("@FArea", farea.Text));
        cmd2.Parameters.Add(new SqlParameter("@FPostalCode", fpost.Text));
        cmd2.Parameters.Add(new SqlParameter("@FCityID", 1));

        cmd2.Parameters.Add(new SqlParameter("@accID", accID));

        conn.Open();
        cmd2.ExecuteNonQuery();
        conn.Close();

        Session["accID"] = accID;
        Response.Redirect("http://www.cairositters.com/GUI/Pages/ParentRegistration2.aspx");
    }

}